<template>
	<view>
		<view class="smart-page-head">
			<view class="smart-page-head-title">checkbox复选框</view>
		</view>	
		<view class="uni-padding-wrap uni-common-mt">
			<view class="uni-title uni-common-mt">默认样式</view>
		    <view>
				<checkbox-group>
					<checkbox value="cb1" checked="true" />选中
					<checkbox value="cb" />未选中
				</checkbox-group>
			</view>
			
			<view class="uni-title uni-common-mt">不同颜色和尺寸的checkbox</view>
			<view>
				<checkbox-group>
					<label style="background-color: bisque;">
						<checkbox value="cb1" checked="true" style="transform: scale(0.7)" />选中
					</label>
					<label>
					    <checkbox value="cb" style="transform: scale(0.7)" />未选中
					</label>
				</checkbox-group>
			</view>
		</view>
		
		<view class="uni-title uni-common-mt">推荐展示样式</view>
		<view class="recommend-group" style="background-color: burlywood;">
			<checkbox-group @change="checkboxChange">
				<label class="uni-list-cell uni-list-cell-pd" v-for="item in items" :key="item.value" 
					   style="background-color: bisque;">
					<view >
						<checkbox :value="item.value" :checked="item.checked" />
					</view>
					<view style="margin-left: 5px;">{{item.name}}</view>
				</label>
			</checkbox-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
		  return {
		    items: [
		      { value: 'opt1', name: '中国', checked: false },
		      { value: 'opt2', name: '美国', checked: true },
		      { value: 'opt3', name: '法国', checked: false },
			  { value: 'opt4', name: '英国', checked: false }
		    ]
		  }
		},
		methods: {
			checkboxChange: function(e){
				var items=this.items,
				    values=e.detail.value;
				for(var i=0,lenI=items.length;i<lenI;++i){
					const item=items[i]
					console.log('i:'+i+'---'+item.name+',index:'
					+values.indexOf(item.value)
					+',isCheck:'+item.checked)
					if(values.indexOf(item.value)>=0){
						this.$set(item,'checked',true)
					}else{
						this.$set(item,'checked',false)
					}
				}
			}
		},
		
	}
</script>

<style>
.uni-list-cell {
  display: flex;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.uni-list-cell:hover {
  background-color: rgba(222, 184, 135, 0.2);
}
</style>